﻿@using MvcContrib.UI.Grid
@using XRM.Security.WebUI.Helpers
@model List<XRM.Security.WebUI.Models.WorkKind.WorkKindModel>
@{
    ViewBag.Title = "Виды работ";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section scripts
{
    @Scripts.Render("~/bundles/gridlibrary")
}

<div>
    @if (Permission.AllowWorkKindEdit())
    {
    <p>
        @Html.ActionLink("Добавить вид работ", "Edit", "WorkKind", null, new { @class = "btn btn-large btn-primary" })
    </p>
    }

    <div class="row">
        <div class="col-md-6">
            <h4>Работы с электронными подписями</h4>
            @{
                var leftItems = Model.Where(x => x.IsLinkedWithSign).OrderByDescending(x => x.IsFixed).ThenBy(s => s.Name).ToList();
                if (leftItems.Any())
                {
                    Html.Grid(leftItems).Columns(column =>
                        {
                            column.For(item => Html.ActionLink(item.Name, "Edit", "WorkKind", new { id = item.Id }, null)).Named("Наименование");
                            column.For(item => item.Description).Named("Описание");

                            if (Permission.AllowWorkKindEdit())
                            {
                                column.Custom(@<text>@Html.Partial("_GridActionsPartial", new ViewDataDictionary { { "Controller", "WorkKind" }, { "Id", item.Id }, { "Visible", !item.IsFixed } })</text>)
                                    .Named("<i class='fa fa-trash-o fa-action'></i>");
                            }
                        }).Attributes(@class => "table table-striped table-bordered", id => "table_id_left")
                        .Empty("Нет данных для отображения")
                        .Render();
                } 
            }
        </div>
        <div class="col-md-6">
            <h4>Работы со СКЗИ, программным и аппаратным обеспечением</h4>
            @{
                var rightItems = Model.Where(x => !x.IsLinkedWithSign).OrderByDescending(x => x.IsFixed).ThenBy(s => s.Name).ToList();
                if (rightItems.Any())
                {
                    Html.Grid(rightItems).Columns(column =>
                        {
                            column.For(item => Html.ActionLink(item.Name, "Edit", "WorkKind", new { id = item.Id }, null)).Named("Наименование");
                            column.For(item => item.Description).Named("Описание");

                            if (Permission.AllowWorkKindEdit())
                            {
                                column.Custom(@<text>@Html.Partial("_GridActionsPartial", new ViewDataDictionary { { "Controller", "WorkKind" }, { "Id", item.Id }, { "Visible", !item.IsFixed } })</text>)
                                      .Named( "<i class='fa fa-trash-o fa-action'></i>" );
                            }
                        }).Attributes(@class => "table table-striped table-bordered", id => "table_id_right")
                        .Empty("Нет данных для отображения")
                        .Render();
                } 
            }
        </div>
    </div>

    
</div>

<script type="text/javascript">
    $(document).ready(function () {
        @if (leftItems.Any())
        {
            if (Permission.AllowWorkKindEdit())
            {
            <text>
            $('#table_id_left').dataTable({
                paging: false,
                bFilter: false,
                bSort: true,
                info: false,
                "aoColumnDefs": [{ 'bSortable': false, 'aTargets': [2] }],
                "aaSorting": []
            });
            </text>
            }
            else
            {
                <text>
                $('#table_id_left').dataTable({
                    paging: false,
                    bFilter: false,
                    bSort: true,
                    info: false,
                    "aaSorting": []
                });
                </text>
            }
        }
        @if (rightItems.Any())
        {
            if (Permission.AllowWorkKindEdit())
            {
            <text>
            $('#table_id_right').dataTable({
                paging: false,
                bFilter: false,
                bSort: true,
                info: false,
                "aoColumnDefs": [{ 'bSortable': false, 'aTargets': [2] }],
                "aaSorting": []
            });
            </text>
            }
            else
            {
            <text>
            $('#table_id_right').dataTable({
                paging: false,
                bFilter: false,
                bSort: true,
                info: false,
                "aaSorting": []
            });
            </text>
            }
        }
        });
</script>